﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess
{
    public class TruyXuatCapNhatKhachHang
    {
        KhachHang _khachhang = new KhachHang();

        public KhachHang khachhang
        {
            get { return _khachhang; }
            set { _khachhang = value; }
        }
        public void CapNhatKhachHang()
        {
            DataProvider dp = new DataProvider();
            dp.KetNoi();
            //string sql = "delete from KHACHHANG where TenTaiKhoan=@TaiKhoan";
            string sql = "Update KHACHHANG set HoTen= @Ten,GioiTinh=@GioiTinh,DiaChi=@DiaChi,NgaySinh=@NgaySinh,Email=@Email,DienThoai=@SDT,SoGiayToTuyThan=@SoGiayTo,LoaiGiayToTuyThan=@LoaiGiayTo,NgayCap=@NgayCap,NuocPhatHanh=@NuocPhatHanh,QuocTich=@QuocTich,EmailPhucHoi=@EmailPhucHoi,SoCreditCard=@Credit,LoaiCreditCard=@LoaiCredit,MatKhau=@MatKhau,NgayHetHanCredit=@NgayHetHan where TenTaiKhoan = @TaiKhoan";
            //
            SqlCommand cm = new SqlCommand(sql, dp.cn);
            cm.CommandType = CommandType.Text;
            cm.Parameters.Add("@Ten", SqlDbType.NVarChar).Value = khachhang.HoTen;
            cm.Parameters.Add("@GioiTinh", SqlDbType.NVarChar).Value = khachhang.GioiTinh;
            cm.Parameters.Add("@Diachi", SqlDbType.NVarChar).Value = khachhang.DiaChi;
            cm.Parameters.Add("@NgaySinh", SqlDbType.Date).Value = khachhang.NgaySinh;
            cm.Parameters.Add("@Email", SqlDbType.VarChar).Value = khachhang.Email;
            cm.Parameters.Add("@SDT", SqlDbType.VarChar).Value = khachhang.DienThoai;
            cm.Parameters.Add("@SoGiayTo", SqlDbType.VarChar).Value = khachhang.SoGiayToTuyThan;
            cm.Parameters.Add("@LoaiGiayTo", SqlDbType.NVarChar).Value = khachhang.LoaiGiayToTuyThan;
            cm.Parameters.Add("@NgayCap", SqlDbType.Date).Value = khachhang.NgayCap;
            cm.Parameters.Add("@NuocPhatHanh", SqlDbType.NVarChar).Value = khachhang.NuocPhatHanh;
            cm.Parameters.Add("@QuocTich", SqlDbType.NVarChar).Value = khachhang.QuocTich;
            
            cm.Parameters.Add("@MatKhau", SqlDbType.VarChar).Value = khachhang.MatKhau;
            cm.Parameters.Add("@EmailPhucHoi", SqlDbType.VarChar).Value = khachhang.EmailPhucHoi;
            //cm.Parameters.Add("@SoDam", SqlDbType.Int).Value = khachhang.SoDam;
            //cm.Parameters.Add("@Hang", SqlDbType.Int).Value = khachhang.HangHoiVien;
            cm.Parameters.Add("@Credit", SqlDbType.VarChar).Value = khachhang.SoCreditCard;
            cm.Parameters.Add("@LoaiCredit", SqlDbType.VarChar).Value = khachhang.LoaiCreditCard;
            cm.Parameters.Add("@NgayHetHan", SqlDbType.Date).Value = khachhang.NgayHetHanCredit;
            cm.Parameters.Add("@TaiKhoan", SqlDbType.VarChar).Value = khachhang.TenTaiKhoan;
            cm.ExecuteNonQuery();
            dp.NgatKetNoi();
        }

        public void CapNhatDamThuong()
        {
            DataProvider dp = new DataProvider();
            dp.KetNoi();
            string sql = "Update KhachHang set SoDam=" + khachhang.SoDam + " where SoTheHoiVien = "+khachhang.SoTheHoiVien+"";
            dp.ExecuteNonQuery(sql);
        }
    }
}
